import { http } from '@/utils/http/axios';
import qs from 'qs';

export interface BasicResponseModel<T = any> {
  code: number;
  message: string;
  result: T;
}

/**
 * @description: 称重列表
 */
export function getGoodsType(params?) {
  return http.request<BasicResponseModel>({
    url: '/weight/weight/goodsType',
    method: 'GET',
    params,
  });
}

export function getGoodsTypePage(params?) {
  return http.request<BasicResponseModel>({
    url: '/weight/goodsType/page',
    method: 'POST',
    params,
    // 加这个是解决 传递数组时 会在参数名后面加上[]
    paramsSerializer: function (params) {
      return qs.stringify(params, { arrayFormat: 'repeat' });
    },
  });
}

export function getWeightNumber(params?) {
  return http.request<BasicResponseModel>({
    url: '/weight/weight/weightNumber',
    method: 'GET',
    params,
  });
}
export function deleteGoodsType(params?) {
  return http.request<BasicResponseModel>(
    {
      url: `/weight/goodsType/${params.id}`,
      method: 'DELETE',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}
export function saveGoodsType(params?) {
  return http.request<BasicResponseModel>(
    {
      url: `/weight/goodsType/add`,
      method: 'GET',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}
export function updateGoodsType(params?) {
  return http.request<BasicResponseModel>(
    {
      url: `/weight/goodsType/${params.id}`,
      method: 'GET',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}
export function getPastFiveYearGoodsTypePrice(goodsType?, dateType?) {
  // 创建请求参数对象
  const requestParams = {};
  
  // 添加goodsType参数
  if (goodsType !== undefined && goodsType !== null) {
    requestParams.goodsType = goodsType;
  }
  
  // 添加dateType参数，将日期类型映射为对应的数值：日->1，周->2，月->3
  if (dateType !== undefined && dateType !== null) {
    let dateTypeValue = 1; // 默认日
    switch(dateType) {
      case '日':
        dateTypeValue = 1;
        break;
      case '周':
        dateTypeValue = 2;
        break;
      case '月':
        dateTypeValue = 3;
        break;
    }
    requestParams.dateType = dateTypeValue;
  }
  
  return http.request<BasicResponseModel>({
    url: '/weight/statistic/getPastFiveYearGoodsTypePrice',
    method: 'GET',
    params: requestParams,
  });
}

export function getPastFiveYearGoodsTypeWeight(goodsType?, dateType?) {
  // 创建请求参数对象
  const requestParams = {};
  
  // 添加goodsType参数
  if (goodsType !== undefined && goodsType !== null) {
    requestParams.goodsType = goodsType;
  }
  
  // 添加dateType参数，将日期类型映射为对应的数值：日->1，周->2，月->3
  if (dateType !== undefined && dateType !== null) {
    let dateTypeValue = 1; // 默认日
    switch(dateType) {
      case '日':
        dateTypeValue = 1;
        break;
      case '周':
        dateTypeValue = 2;
        break;
      case '月':
        dateTypeValue = 3;
        break;
    }
    requestParams.dateType = dateTypeValue;
  }
  
  return http.request<BasicResponseModel>({
    url: '/weight/statistic/getPastFiveYearGoodsTypeWeight',
    method: 'GET',
    params: requestParams,
  });
}

// export function getOrderItemList(params?) {
//   return http.request<BasicResponseModel>({
//     url: `/order/order/item/list`,
//     method: 'GET',
//     params,
//   });
// }
// /**
//  * 获取物流公司列表
//  * @param params
//  */
// export function getLogisticsList(params?) {
//   return http.request({
//     url: '/order/order/logistics',
//     method: 'GET',
//     params,
//   });
// }
// /**
//  * 订单发货
//  * @param params
//  */
// export function orderShipment(params?) {
//   return http.request<BasicResponseModel>(
//     {
//       url: `/order/order/shipment`,
//       method: 'PUT',
//       params,
//     },
//     {
//       isTransformResponse: false,
//       joinParamsToUrl: true,
//     }
//   );
// }
